//
//  ZJStatuesCell.swift
//  Webo
//
//  Created by 曾静 on 16/6/27.
//  Copyright © 2016年 qq. All rights reserved.
//

import UIKit
import SnapKit

let OriginalMargin:CGFloat = 10
class ZJStatuesCell: UITableViewCell {

    
    var thirdTopContstrait:Constraint?
    var status:ZJStatues?{
        
        didSet{
            
            firstView.status = status
            
            secondView.status = status
            
            thirdTopContstrait?.uninstall()
            
            if status?.retweeted_status == nil{
                
                secondView.hidden = true
                
               thirdView.snp_makeConstraints(closure: { (make) -> Void in
                
              thirdTopContstrait = make.top.equalTo(firstView.snp_bottom).constraint
                
               })
                
            }else{
                
                secondView.hidden = false

               thirdView.snp_makeConstraints(closure: { (make) -> Void in
                    
                   thirdTopContstrait =   make.top.equalTo(secondView.snp_bottom).constraint
                })
                
            }
            
            thirdView.status = status
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        
      backgroundColor = RGB(237, green: 237, blue: 237)
        
        //一定记得
        contentView.addSubview(firstView)
        
        contentView.addSubview(secondView)
    
        contentView.addSubview(thirdView)
        
        firstView.snp_makeConstraints { (make) -> Void in
            
            make.leading.trailing.equalTo(contentView)
            make.top.equalTo(contentView).offset(8)
 
        }
        
        secondView.snp_makeConstraints { (make) -> Void in
            
            make.leading.trailing.equalTo(contentView)
            
            make.top.equalTo(firstView.snp_bottom)
        }
        
        thirdView.snp_makeConstraints { (make) -> Void in
            
           make.leading.trailing.equalTo(contentView)
            
           thirdTopContstrait = make.top.equalTo(secondView.snp_bottom).constraint
            
            make.height.equalTo(35)
        }
        
        
        
        contentView.snp_makeConstraints { (make) -> Void in
            
            make.top.leading.trailing.equalTo(self)

            make.bottom.equalTo(thirdView)
            
        }
        
        
    }
    
    
    //懒加载三个View
    private lazy var firstView :ZJOriginalView = ZJOriginalView()
    
    private lazy var secondView :ZJOthersView = ZJOthersView()
    
    private lazy var thirdView:ZJThreeButtonView = ZJThreeButtonView()
}
